//新增修改订单信息
export const addOrderApi = async (type, data) => {
	//0 : 团购 , 1:普通商品
	let url = '/api/orderInfo/addOrUpdateOrderInfo'
	if (type === '0') {
		url = '/api/orderInfo/placeGroupOrder'
	}
	const {
		data: res
	} = await uni.$http.post(url, data)
	return res
}

//预支付
export const prepaymentApi = async (orderId, payType, number) => {
	let url = ''
	if (number) {
		url = `/api/wxPay/pay/${orderId}/${payType}?payPassword=${number}`
	} else {
		url = `/api/wxPay/pay/${orderId}/${payType}`
	}
	const {
		data: res
	} = await uni.$http.get(url)
	return res
}

//积分商品支付 
export const integralPaymentApi = async (price, productName, skuCode) => {
	const {
		data: res
	} = await uni.$http.post(
		`/api/integral/product/pay?price=${price}&productName=${productName}&skuCode=${skuCode}`)
	return res
}

//生成签名
export const addSignApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/wxPay/addSign', data)
	return res
}

//查询单个订单支付状态
export const getOrderStatusApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.get(`/api/wxPay/queryPayStatus/${orderId}`)
	return res
}

//查询单个订单详情
export const getOrderDetailApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.get(`/api/orderInfo/findOrderDetails/${orderId}`)
	return res
}

//订单列表分页查询
export const getOrderListApi = async (data) => {
	const {

		data: res
	} = await uni.$http.post('/api/orderInfo/queryAppListByPage', data)
	return res
}

//取消订单
export const cancelOrderApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.post(`/api/orderInfo/cancelOrder/${orderId}`)
	return res
}

//新增订单申请退款
export const addApplyRefundApi = async (data) => {
	const {
		data: res
	} = await uni.$http.post('/api/wxPay/addApplyForRefund', data)
	return res
}

//确认收货
export const confirmOrderApi = async (orderId) => {
	const {
		data: res
	} = await uni.$http.post(`/api/orderInfo/confirmOrder/${orderId}`)
	return res
}

export const orderTypeApi = async (orderId, payType) => {
	const {
		data: res
	} = await uni.$http.post(`/api/wxPay/pay/${orderId}/${payType}`)
	return res
}

//查询各订单数量
export const getOrderCountApi = async () => {
	const {
		data: res
	} = await uni.$http.get('/api/orderInfo/miniApp/countByStatus')
	return res
}

export const findCurrentUerCoupon = async (data) => {
	const { data: res } = await uni.$http.post(`/api/findCurrentUerCoupon`, data)
	return res
}